package com.fsp.blog.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fsp.blog.admin.dao.AdminMapper;
import com.fsp.blog.admin.dao.PermissionMapper;
import com.fsp.blog.admin.pojo.Admin;
import com.fsp.blog.admin.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author fushengping
 * @className AdminService
 * @description
 * @date 2021/11/24 21:48
 */
@Service
public class AdminService {
    @Resource
    private AdminMapper adminMapper;
    @Resource
    private PermissionMapper permissionMapper;

    public Admin findAdminByUserName(String username) {
        LambdaQueryWrapper<Admin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Admin::getUsername,username).last("limit 1");
        return this.adminMapper.selectOne(queryWrapper);
    }

    //根据用户id,查询用户的资源路径集合
    public List<Permission> findPermissionsByAdminId(Long adminId) {
        return permissionMapper.findPermissionsByAdminId(adminId);
    }
}
